﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace Zo.Events
{
    /// <summary>
    /// 事件发布者。
    /// </summary>
    public interface IEventPublisher : IDisposable
    {
        /// <summary>
        /// 发布。
        /// </summary>
        /// <typeparam name="TEvent">事件类型。</typeparam>
        /// <param name="event">事件。</param>
        /// <returns>事件处理结果。</returns>
        IEventResult Publish<TEvent>(TEvent @event) where TEvent : IEvent;

        /// <summary>
        /// 发布。
        /// </summary>
        /// <typeparam name="TEvent">事件类型。</typeparam>
        /// <param name="event">事件。</param>
        /// <param name="cancellationToken">取消操作通知。</param>
        /// <returns>事件处理结果。</returns>
        Task PublishAsync<TEvent>(TEvent @event, CancellationToken cancellationToken = default) where TEvent : IEvent;
    }
}